package ipebg.mzk.common.util;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.foxconn.shzbg.directory.service.DirectoryAuthService;

public class DirectoryUtil {
	public static DirectoryAuthService getDirectoryService() throws Exception {

		DirectoryAuthService directoryService;
		Properties props = new Properties();
		props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
		props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming");
		// props.setProperty(Context.PROVIDER_URL, "10.197.10.88:1099");
		props.setProperty(Context.PROVIDER_URL, "10.197.10.183:1099");
		props.setProperty(Context.SECURITY_PRINCIPAL, "eSign");
		props.setProperty(Context.SECURITY_CREDENTIALS, "esign.shzbg");

		try {
			InitialContext ctx = new InitialContext(props);
			directoryService = (DirectoryAuthService) ctx.lookup("/sip/directory/auth/remote");
		} catch (NamingException e) {
			throw new Exception("獲取目錄服務時出錯了...");
		}
		return directoryService;
	}
}
